﻿using System.Collections.Generic;
using System.Linq;

namespace LBSoft.Common.DotNetExt
{
    public static class ExtDictionary
    {
        /// <summary>
        /// 获得字典中key对应的value 如果为null 返回默认值
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="source"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static TValue GetValue<TKey,TValue>(this Dictionary<TKey,TValue> source, TKey key)
        {
            if (!source.Keys.Contains(key))
            {
                return default(TValue);
            }
            return source[key];
        }
    }
}
